package com.ruoyi.web.controller.books;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.books.domain.BooksAll;
import com.ruoyi.books.service.IBooksAllService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 非遗项目汇总Controller
 *
 * @author FeiYiLand
 * @date 2024-03-25
 */
@Anonymous
@RestController
@RequestMapping("/books/all")
public class BooksAllController extends BaseController
{
    @Autowired
    private IBooksAllService booksAllService;

    /**
     *    books_history
     *    根据allId查询history所有
     */
    @GetMapping(value = "/history/{allId}")
    public AjaxResult getHistoryAll(@PathVariable("allId") Long allId){
        return success(booksAllService.selectBooksHistoryByAllId(allId));
    }
    /**
     * 查询非遗项目汇总列表
     */
//    @PreAuthorize("@ss.hasPermi('books:all:list')")
    @GetMapping("/list")
    public TableDataInfo list(BooksAll booksAll)
    {
        startPage();
        List<BooksAll> list = booksAllService.selectBooksAllList(booksAll);
        return getDataTable(list);
    }

    /**
     * 导出非遗项目汇总列表
     */
//    @PreAuthorize("@ss.hasPermi('books:all:export')")
    @Log(title = "非遗项目汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BooksAll booksAll)
    {
        List<BooksAll> list = booksAllService.selectBooksAllList(booksAll);
        ExcelUtil<BooksAll> util = new ExcelUtil<BooksAll>(BooksAll.class);
        util.exportExcel(response, list, "非遗项目汇总数据");
    }

    /**
     * 获取非遗项目汇总详细信息
     */
//    @PreAuthorize("@ss.hasPermi('books:all:query')")
    @GetMapping(value = "/{allId}")
    public AjaxResult getInfo(@PathVariable("allId") Long allId)
    {
        return success(booksAllService.selectBooksAllByAllId(allId));
    }

    /**
     * 新增非遗项目汇总
     */
//    @PreAuthorize("@ss.hasPermi('books:all:add')")
    @Log(title = "非遗项目汇总", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BooksAll booksAll)
    {
        return toAjax(booksAllService.insertBooksAll(booksAll));
    }

    /**
     * 修改非遗项目汇总
     */
//    @PreAuthorize("@ss.hasPermi('books:all:edit')")
    @Log(title = "非遗项目汇总", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BooksAll booksAll)
    {
        return toAjax(booksAllService.updateBooksAll(booksAll));
    }

    /**
     * 删除非遗项目汇总
     */
//    @PreAuthorize("@ss.hasPermi('books:all:remove')")
    @Log(title = "非遗项目汇总", businessType = BusinessType.DELETE)
	@DeleteMapping("/{allIds}")
    public AjaxResult remove(@PathVariable Long[] allIds)
    {
        return toAjax(booksAllService.deleteBooksAllByAllIds(allIds));
    }
}
